<? 
	if(isset($_POST['btndelete']))
	{
		require("required/dbconnect.php");
		$deleteIds="";
		if(!empty($_POST['pro_id']))
		{
			$postCount = count($_POST['pro_id']);
			$msg="";
			
			
			if($postCount!=0)
			{
				for ( $i=0; $i < $postCount; $i++ ) 
				{
					$deleteIds .= $_POST['pro_id'][$i].',';
				}
				$deleteIds = rtrim($deleteIds,',');
				mysql_query('delete from os_favorite where id in ('.$deleteIds.')');
			}
		}
		header("Location:os_myfav.php");
	}
	
	if(isset($_POST['btngo']))
	{
		require("required/dbconnect.php");
		$pageno=$_POST['pageno'];
		$id=$_POST['id'];
		header("Location:os_myfav.php?page=$pageno&id=$id");
	}
	$title="My Wish List";
	require("required/dbconnect.php");
	require("required/share_function.php");
	require("required/header.php"); 
	
	

	if(empty($_GET['page']))
	{
		$page="1";
	}
	else
	{
		$page=$_GET['page'];
	}
	
	$totalperpage=10;

	$from=($page-1)*$totalperpage;	
	$get_fav=mysql_query("select * from os_favorite where uid=$member_id order by add_datetime desc limit $from,$totalperpage")or die(mysql_error());
	$get_total=mysql_query("select * from os_favorite where uid=$member_id")or die(mysql_error());
	
	
	$count=mysql_num_rows($get_total);

	$totalpage=$count/$totalperpage;
	
	if($count%$totalperpage>0)
	{
		if(round($totalpage)>$totalpage)
		{
			$totalpage=round($totalpage);
		}
		else
		{
			$totalpage=round($totalpage+1);
		}
	}
	else
	{
		$totalpage=round($totalpage);
	}
	
	
	$nextpage=$page+1;
	$prepage=$page-1;
	$tr1="";
	$tr2="";


?>
<SCRIPT LANGUAGE="JavaScript">
		function checkall(form, prefix, checkall) 
		{
			var checkall = checkall ? checkall : 'chkall';
			for(var i = 0; i < form.elements.length; i++) {
				var e = form.elements[i];
				if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
					e.checked = form.elements[checkall].checked;
				}
			}
		}
		
		function checkfields(frm)
		{
		if(confirm("Confirm to delete?"))
		return true;
		else
		return false;
		}
		//  End -->
	</script>
			
				<table width="100%" cellpadding="6" cellspacing="0">
					<td align="left" class="page_title_bar" width="100%">
					 My Wish List
					</td>
					
					<tr>
						<Td height="300" valign="top"><font class="page_description">This is where you can store a collection of your favourite items. </font><br>
							<table width="100%">
							<?	
								if($count==0)
								{
							?>
								<tr>
									<td align="center"> :: NO RECORD :: </td>
								</tr>
							<?	
								}
								else
								{
							?>
							<tr>
								<td width="" colspan="6" align="left">
									<table width="100%" cellpadding="0" cellspacing="0" >
										<td width="69%" height="45">
										<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" >
										<input type="button" class="button" value="<<" onClick="window.open('os_myfav.php?page=1&id=<?= $id ?>','_self')">
										<input type="button" class="button" value="<" onClick="window.open('os_myfav.php?page=<?= $prepage ?>&id=<?= $id ?>','_self')">
										
										Page <input type="text" name="pageno" value="<?= $page ?>" size="2" maxlength="3" class="text"> of <?= $totalpage ?>
										<input type="hidden" name="id" value="<?= $id ?>">
										<input type="submit" value="Go" class="button" name="btngo">
										<? if($page==$totalpage){ ?>	
										<input type="button" class="button" value=">" >
										<? }else{ ?>
										<input type="button" class="button" value=">" onClick="window.open('os_myfav.php?page=<?= $nextpage ?>&id=<?= $id ?>','_self')">
										<? } ?>
										<input type="button" class="button" value=">>" onClick="window.open('os_myfav.php?page=<?= $totalpage ?>&id=<?= $id ?>','_self')">
										
										</form>
										
										</td>
										
									</table>
								</td>
							</tr>
							<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm" onsubmit="return checkfields(this);">
							<tr>
								<td><table width="100%" bgcolor="#CCCCCC" cellpadding="1" cellspacing="1">
								<tr class='table_header' align="center">
									<td width="5%"><input class="checkbox" type="checkbox" name="chkall" onclick="checkall(this.form)"></td><td width="39%">Product</td><td width="17%">Product code</td><td width="22%">Add date</td>
								</tr>
							<?
									$no=0;
									while($f=mysql_fetch_array($get_fav))
									{
										$get_product=mysql_query("select * from os_products where id=".$f['pid']);
										$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
										
										$get_pic=mysql_query("select * from os_productpic where product_id='".$a['id']."' order by order_id asc limit 1")or die(mysql_error());
					
										if(mysql_num_rows($get_pic)==0)
										{
											$pic="empty";
											$piclink="noimage.jpg";
											$fix="";
										}
										else
										{
											$pic=mysql_fetch_array($get_pic,MYSQL_ASSOC);
											
											$piclink=$pic['name'];
											
											if($pic["width"]-$pic["height"]>0)
											{
												$fix="width=155";
											}
											else
											{
												$fix="height=130";
											}
										}	
																				
										if($no%2==0)
										{
											$class1="table_item_even";
											$class2="table_item_odd";
										}
										else
										{
											$class1="table_item_odd";
											$class2="table_item_even";
										}					
										
																				
							?>
								 <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" onmouseout="this.className='<?= $class1 ?>'" align="center">
									
                                    <td>
										<input type="checkbox" name="pro_id[]" value="<?= $f["id"] ?>">
									</td>
									<td align="center">
                                    	<table width="80%" cellpadding="5" align="center">
											<Td width="12%">
												<a href="os_view_full.php?id=<?= $a['id'] ?>"><img border=0 src="productpic/thumbnails/<?= $piclink ?>" <?= $fix ?>></a>
											</Td>
											<td width="88%" valign="top">
												<a href="os_view_full.php?id=<?= $a['id'] ?>"><?= $a['product_name_eng'] ?></a><br>
												
											</td>
										</table>
									</td>
                                   
                                    <td><?= $a['product_code'] ?></td>
                                    <td><?= $f['add_datetime'] ?></td>
								</tr>
							<? 
								$no++;	
									} 
							?>
							<?= $tr2 ?>
							
							
							</table></td>
							</tr>
							<tr>
							<td colspan="4"><input type="submit" value="Delete" class="button" name="btndelete"></td>
							</tr>
							</form>
							<?
								}
							?>
							</table>
							
						</Td>
					</tr>		  
			  	</table>
			
<? require("required/footer.php"); ?>	